<!--护理等级管理页-->
<template>
  <!-- 大标题 -->
  <div style="height: 6vh;padding: 10px 20px;background-color: #fff">
    <span style="line-height: 60px;font-size: 20px;font-weight: bold">护理等级管理</span>
  </div>
  <!-- 搜索卡片 -->
  <el-card style="margin-top: 10px;height: 70px;">
    <el-form :inline="true">
      <el-form-item label="项目名称" style="width: 220px;">
        <el-input placeholder="请输入"  v-model="searchRangeForm.name" @keydown="loadRange"></el-input>
      </el-form-item>
      <el-form-item label="启用状态" style="width: 290px;">
        <el-select placeholder="请选择" v-model="searchRangeForm.status"  @change="loadRange">
          <el-option label="启用" value="1"></el-option>
          <el-option label="禁用" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button round :icon="Refresh" type="info" @click="loadRange(searchRangeForm = {})">重置</el-button>
        <el-button type="primary" :icon="Search" @click="loadRange">查询</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 项目数据卡片 -->
  <el-card style="margin-top: 10px;">
    <el-button style="float: right;margin-bottom: 10px" :icon="Edit" type="primary" @click="beforeAddProject">新增护理等级</el-button>
    <el-table :data="RangeArr">
      <el-table-column label="序号" type="index" width="80" align="center"></el-table-column>
      <el-table-column label="护理等级名称" prop="name" align="center"></el-table-column>
      <el-table-column label="护理执行计划" prop="pname" align="center"></el-table-column>
      <el-table-column label="护理费用(元/月)" prop="fee" align="center"></el-table-column>
      <el-table-column label="等级说明" prop="description" align="center"></el-table-column>
      <el-table-column label="创建人" prop="cname" align="center"></el-table-column>
      <el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center">
        <template #default="scope">
          <el-switch :active-value="'1'" :inactive-value="'0'" v-model="scope.row.status"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button :icon="Edit">编辑</el-button>
          <el-button :icon="Delete" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>

  <!-- 新建项目弹窗(对话框) -->
  <el-dialog
      :title="dialogTitle"
      v-model="dialogVisible"
      style="padding: 40px;"
      destroy-on-close
      @close="handleClose"
  >
    <SimpleForm
        v-model="form"
        @submitSuccess="onSubmitSuccess"
        @cancel-form="dialogVisible = false"
        :form-config="addRangeForm"
    />
  </el-dialog>
</template>

<script setup>
import {Delete, Edit, Refresh, Search} from "@element-plus/icons-vue";
import {onMounted, ref} from "vue";
import {addRangeForm} from "@/utils/formItemsConfig.js";
import SimpleForm from "@/components/SimpleForm/index.vue";
import {loadRangeApi} from "@/api/nursing/nursingRange.js";


const form = ref({});//表单数据

//定义变量控制弹窗是否出现
const dialogVisible=ref(false);
//定义变量用来保存弹窗的标题
const dialogTitle=ref('新增项目');
//点击"新建用户"按钮，让弹窗出现且改标题
const beforeAddProject=()=>{
  dialogTitle.value="新增护理";
  dialogVisible.value=true;
}

//处理弹窗关闭的方法
const handleClose=()=>{
  if(confirm("确定要关闭弹窗吗?")){
    //关闭弹窗且清空已输入的数据
    dialogVisible.value=false;
    form.value={};
  }
}

//数据显示
//定义数组用来保存用户表格数据
const RangeArr=ref([]);
//定义对象用来保存搜索卡片的用户搜索条件
const searchRangeForm=ref({name:'',status:''});
//定义加载用户数据的方法
const loadRange=async ()=>{
  // let data=qs.stringify(searchProjectForm.value);  //将对象转换为字符串
  const list = await loadRangeApi(searchRangeForm.value);
  RangeArr.value = list;
  console.log(list);
  console.log(RangeArr.value);
};

onMounted(loadRange);
</script>